package org.shoukaiseki.tools.mybatis.generator.db;

import lombok.extern.slf4j.Slf4j;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Properties;

/**
 * @ClassName DBConnectionPool
 * @Description TODO:
 * @Author Rick
 * @Date 2018/9/21 10:43
 * @Vesion 1.0.0
 */
//@Slf4j
//public class DBConnectionPool {
//
//
//    private static ThreadLocal<Connection> connectionThreadLocal = new ThreadLocal<Connection>();
//    private static DataSource druidDataSource = null;
//
//
//    public static Connection getConnection(String url,String user,String pwd) {
//        Properties properties = new Properties();
//        properties.put("driverClassName","com.mysql.cj.jdbc.Driver");
//        properties.put("url",url);
//        properties.put("username",user);
//        properties.put("password",pwd);
//        properties.put("initialSize","20");
//        properties.put("maxActive","100");
//        properties.put("maxWait","60000");
//        properties.put("timeBetweenEvictionRunsMillis","60000");
//        properties.put("minEvictableIdleTimeMillis","300000");
//        Connection connection = null;
//        try {
//            druidDataSource = (DruidDataSource) DruidDataSourceFactory.createDataSource(properties);
//            connection = connectionThreadLocal.get();
//            if(null == connection){
//                connection = druidDataSource.getConnection();
//                connectionThreadLocal.set(connection);
//            }
//        } catch (SQLException e) {
//            log.error("[JDBC Exception] >> message:" + e.getMessage());
//        } catch (Exception e1){
//            log.error(e1.getMessage());
//        }
//        return connection;
//    }
//
//    public static void closeConnection() {
//        Connection connection = connectionThreadLocal.get();
//        if(null != connection){
//            try {
//                connection.close();
//                connectionThreadLocal.remove();
//            } catch (SQLException e) {
//                log.error("[JDBC Exception] >> message:" + e.getMessage());
//            }
//        }
//    }
//}
